package cn.lg.soar.xxljob;

import cn.lg.soar.common.util.data.DataUtil;
import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import org.springframework.context.annotation.Bean;

/**
 * @author luguoxiang 469599794@qq.com
 * @Date: 2024/2/23 16:30
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class XxlJobConfig {
 
    private final XxlJobProps props;

    public XxlJobConfig(XxlJobProps props) {
        this.props = props;
    }

    @Bean
    public XxlJobSpringExecutor xxlJobExecutor() {
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(props.getAdminAddresses());
        xxlJobSpringExecutor.setAppname(props.getAppName());
        if (DataUtil.isValuable(props.getIp())) {
            xxlJobSpringExecutor.setIp(props.getIp());
        }
        if (DataUtil.isValuable(props.getPort())) {
            xxlJobSpringExecutor.setPort(props.getPort());
        }
        xxlJobSpringExecutor.setAccessToken(props.getAccessToken());
        xxlJobSpringExecutor.setLogPath(props.getLogPath());
        xxlJobSpringExecutor.setLogRetentionDays(props.getLogRetentionDays());
 
        return xxlJobSpringExecutor;
    }

}